package com.second.hand.trading.server.controller;

import com.second.hand.trading.server.model.IntergralModel;
import com.second.hand.trading.server.service.IntergralService;
import com.second.hand.trading.server.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("/intergral")
@RestController
public class IntergralController {
    private final IntergralService intergralService;

    public IntergralController(IntergralService intergralService) {
        this.intergralService = intergralService;
    }

    /**
     * 用户签到加积分
     * @param token
     * @return
     */
    @PostMapping("/incr")
    public ResultVo incrIntergral(@RequestHeader("token") String token) {
        intergralService.incrIntergral(token);
        return ResultVo.success();
    }

    /**
     * 获取当前登录用户的签到信息
     * @return
     */
    @GetMapping("/get")
    public ResultVo getCurrentUserIntergral(@RequestHeader("token") String token){
        return ResultVo.success(intergralService.getIntergral(token));
    }

    @PostMapping("/decr")
    public ResultVo decrIntergral(@RequestHeader("token") String token,Integer type){
        intergralService.decrIntergral(token,type);
        return ResultVo.success();
    }
}
